<?php

class Db_Tables_ParamsCatindex extends Zend_Db_Table
{
    protected $_name = 'params_catindex';
	
	function GetCid($leafCatId)
	{
		$cid = 0;
		
		if($leafCatId)
		{
			$row = $this->fetchRow("cat_id='".$leafCatId."'");
			
			if($row)
			{
				if($row['cid'])
				{
					$cid = $row['cid'];
				}else{
					$txt = $row['cat_txt'];
					$txt = trim($txt);

					if($txt)
					{
						$ex = explode(">>", $txt);
						
						if(is_array($ex))
						{
							if(count($ex))
							{
								$key = $ex[0];
								
								if($key)
								{
									$mod = new Db_Tables_BjmCategories();
									$cid = $mod->GetCid($key);
								}
							}
						}
					}
				}
			}
		}
		
		return $cid;
	}
}